import java.util.*;
public class AnagramsTogether{
	public static  void bringAnagramsTogether(String inputArray[], int n){
		String[] words = new String[n];
		int[] index = new int[n];
		char[] tempSorted;
		for(int i = 0; i < n; i++)
		{
			index[i] = i;
		}

		for(int i = 0; i < n; i++)
		{
			
			tempSorted = inputArray[i].toCharArray();
			Arrays.sort(tempSorted);
			words[i] = String.valueOf(tempSorted);

		}

		for(int i = 0; i < n-1; i++)
		{
			for(int j = i+1; j < n; j++)
			{
				if(words[j].compareTo(words[i]) < 0)
				{
					String temp = words[j];
					int temp1 = index[j];
					words[j] = words[i];
					index[j] = index[i];
					words[i] = temp; 
					index[i] = temp1;
				}
			}
		}

		for(int i = 0; i < n; i++)
		{
			System.out.println(inputArray[index[i]]);
		}

	}

	public static void main(String[] args) {
		String[] inputArray = {"act", "dog", "cat", "god", "tca", "why","yhw","hyu"};
		bringAnagramsTogether(inputArray,inputArray.length);
	}
}